package com.blank.task11;

import java.util.Arrays;

/**
 * 编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打 印出来。
 */
public class NumCount {
    public static void main(String[] args) {
        //目标字符串的初始化
        String str = new String("ABCD123!@#$%ab");
        //声明一个一维数组来记录arr1
        char[] arr1 = str.toCharArray();
        int[] arr2 = new int[str.length()];
        System.out.println(Arrays.toString(arr1));
        for (int i=0;i<str.length();i++){
           int k = (int)arr1[i];
           arr2[i] = k;
        }
        System.out.println(Arrays.toString(arr2));
        int iA = 0;  //表示字符串中大写字母的个数并打印
        int ia = 0;   //小写字母
        int i0 = 0;
        int ie = 0;
        String Upper = "";   //大写字母字符串
        String Lower = "";   //小写字母字符串
        String Num = "";    //数字字符串
        String Else = "";   //其他字符
        //根据ASCII码值的区间进行相应的判断
        for(int i:arr2){
            if(i>=65&&i<=90){
                iA++;
                Upper += (char)i;
            }else if(i>=97&&i<=122){
                ia++;
                Lower += (char)i;
            }else if(i>=48&&i<=57){
                i0++;
                Num += (char)i;
            }else{
                ie++;
                Else += (char)i;
            }
        }
        //进行输出打印
        System.out.println("大写字母个数:"+iA+",小写字母个数"+ia+",数字个数"+i0+",其他字符"+ie);
        System.out.println(Upper.toString());
        System.out.println(Lower.toString());
        System.out.println(Num.toString());
        System.out.println(Else.toString());
    }
}
